import { readStrFromFile, saveStrToFile } from "../utils/mirUtil";


export function readAndWriteMap(){
    let str=readStrFromFile("配置/defmap.json")
    let mapset=JSON.parse(str)

    let freshMon=[];

    for(let i=0;i<mapset.Config.length;i++)
    {
        let mapItem=mapset.Config[i];
        if(mapItem.MapName=="0")
        {
            continue;
        }
        let MonGen=mapItem.MonGen;
        mapItem.MonGen=[];

        
        if(MonGen&&MonGen.length>0)
        {
            let newMapItem={
                mapId:mapItem.MapName,
                mapName:mapItem.Name,
                monList:[],
            }
            freshMon.push(newMapItem)
            let map={};
            for(let j=0;j<MonGen.length;j++)
            {
                let monSetItem=MonGen[j];
                let obj=map[monSetItem.Name]
                if(!obj)
                {
                    obj={
                        name:monSetItem.Name,
                        num:0,
                        interval:monSetItem.ZenTime,
                    }
                    map[monSetItem.Name]=obj
                    newMapItem.monList.push(obj)
                }
                obj.num+=monSetItem.Count;
                
            }
        }
    }

    saveStrToFile("配置/newmap.json",JSON.stringify(mapset))
    saveStrToFile("配置/mongen.json",JSON.stringify(freshMon))
}